package org.wangblue.document;

import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.action.delete.DeleteResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.wangblue.common.Client;

import java.io.IOException;

/**
 * @Description: 删除文档
 * @Author: WangBlue
 * @Create: 2024-10-24 10:20
 * @Version: 1.0
 **/

public class DeleteDocument {
    private static final String INDEX_NAME = "user";
    private static final String ID = "1001";
    public static void main(String[] args) throws IOException {
        // 1. 创建客户端实例
        RestHighLevelClient client = Client.getClient();

        // 2. 创建请求对象
        DeleteRequest request = new DeleteRequest(INDEX_NAME, ID);

        // 3. 执行请求
        try {
            DeleteResponse response = client.delete(request, RequestOptions.DEFAULT);
            System.out.println("删除成功：" + response.toString());
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            client.close();
        }

    }
}
